:: Set encodeing to UTF-8 for console
@CHCP 65001
:: 安装thmar的依赖库(mingw,esp32)
:: 依赖库: cmake, conan, python3

ECHO OFF 
SETLOCAL

where gcc
if errorlevel 1 (
	ECHO gcc NOT FOUND.
	exit /B -1
)
ECHO gcc found

where cmake
if errorlevel 1 (
	ECHO cmake NOT FOUND.
	exit /B -1
)
ECHO cmake found
where conan
if errorlevel 1 (
	ECHO conan NOT FOUND.
	exit /B -1
)
ECHO conan found
:: 检查conan 版本,要求conan 2
conan --version | findstr /C:"Conan version 2"
if errorlevel 1 (
	ECHO coan 2 required.
	exit /B -1
)
:: 检查conan 版本,要求conan 2
conan --version | findstr /C:"Conan version 2"
if errorlevel 1 (
	ECHO coan 2 required.
	exit /B -1
)
where python
if errorlevel 1 (
	ECHO python NOT FOUND.
	exit /B -1
)
ECHO python found
:: 检查Python 版本,要求Python 3
python --version | findstr /C:"Python 3"
if errorlevel 1 (
	ECHO python 3 required.
	exit /B -1
)

SET sh_folder=%~dp0
:: 删除最后的 '\'
SET sh_folder=%sh_folder:~0,-1%
SET build_type=Release

:: parse command arguments
:loop
IF x%1 == x GOTO :pare_end
IF /I "%1" == "/RELEASE" SET build_type=Release
IF /I "%1" == "/DEBUG" SET build_type=Debug
SHIFT
GOTO :loop
:pare_end

echo build type: %build_type%

:: 调用gcc -dumpmachine命令并将输出保存到变量GCC_MACHINE中
for /f "delims=" %%i in ('gcc -dumpmachine') do set GCC_MACHINE=%%i

:: 显示获取到的machine信息
echo machine: %GCC_MACHINE%

conan install %sh_folder% -of %sh_folder%\build\%GCC_MACHINE% ^
	-s build_type=%build_type% -o build_test=True -o with_paho=True ^
	--build missing  

:: -pr:h esp32_gcc 指定目标平台的profile
:: -pr:b default  指定编译平台的profile
:: --build missing 编译缺少的依赖库

ENDLOCAL